import toffee
from toffee.agent import *


class FIFOAgent(toffee.agent.Agent):
    def __init__(self, read_bundle, write_bundle, internal_bundle):
        # 将 read_bundle 传给父类以获取时钟
        super().__init__(read_bundle)

        self.read_bundle = read_bundle
        self.write_bundle = write_bundle
        # self.internal_bundle = internal_bundle
        
        self.write_bundle.rst_n.AsRiseWrite()

    @driver_method()
    async def reset(self):
        self.write_bundle.enqueue((0, 0, 0, 0))
        await self.write_bundle.step()

        self.write_bundle.enqueue((1, 0, 0, 0))
        await self.write_bundle.step()

    @driver_method()
    async def enqueue(self, data):
        self.write_bundle.enqueue(data)
        await self.monitor_step()

    @driver_method()
    async def dequeue(self):
        await self.monitor_step()
        return self.read_bundle.dequeue()
